package com.tanhua.app.service;

import com.tanhua.api.mongo.PublishApi;
import com.tanhua.app.interceptor.UserHolder;
import com.tanhua.domain.mongo.Publish;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class QuanZiMqService {

    @Reference
    private PublishApi publishApi;

    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    //实现发送历史行为到消息中间件
    public void sendMsg(String publishId, int type) {
        // 获取当前登录用户的id
        Long userId = UserHolder.getUser().getId();
        // 创建Map集合 组装数据
        Map map=new HashMap();
        map.put("userId",userId);
        map.put("type",type);
        map.put("publishId",publishId);
        //在组装一下大数据程序需要的pid
        Publish publish = publishApi.findByIdtoPublish(publishId);
        map.put("pid",publish.getPid());

        rocketMQTemplate.convertAndSend("tanhua-quanzi",map);
        System.out.println("往消息中间件中存入了当前用户的历史行为");

    }
}
